﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.Core.Prototype;
using System.Diagnostics.Contracts;

namespace YasharEl.Infrastructure.Core.EntityModel.Prototype
{
    public static class PropertyInstanceValueFactory
    {
        public static IPropertyInstanceValue CreateValueReference(IPropertyInstance propertyInstance)
        {
            Contract.Requires<ArgumentNullException>(propertyInstance != null, "propertyInstance could not be null.");

            IPropertyInstanceValue valueEntity = null;
            if (propertyInstance.PropertyMapping.PropertyDefinition.DataType == DataType.Integer)
            {
                valueEntity = new PropertyInstanceIntegerValueEntity();
            }

            if (propertyInstance.PropertyMapping.PropertyDefinition.DataType == DataType.Long)
            {
                valueEntity = new PropertyInstanceLongValueEntity();
            }

            if (propertyInstance.PropertyMapping.PropertyDefinition.DataType == DataType.String)
            {
                valueEntity = new PropertyInstanceInfinityStringValueEntity();
            }

            if (propertyInstance.PropertyMapping.PropertyDefinition.DataType == DataType.Double)
            {
                valueEntity = new PropertyInstanceDoubleValueEntity();
            }

            if (propertyInstance.PropertyMapping.PropertyDefinition.DataType == DataType.Decimal)
            {
                valueEntity = new PropertyInstanceDecimalValueEntity();
            }

            if (propertyInstance.PropertyMapping.PropertyDefinition.DataType == DataType.DateTime)
            {
                valueEntity = new PropertyInstanceDateTimeValueEntity();
            }

            if (propertyInstance.PropertyMapping.PropertyDefinition.DataType == DataType.Boolean)
            {
                valueEntity = new PropertyInstanceBooleanValueEntity();
            }

            if (propertyInstance.PropertyMapping.PropertyDefinition.DataType == DataType.Address)
            {
                valueEntity = new PropertyInstanceAddressValueEntity();
            }

            if (valueEntity != null)
            {
                return valueEntity;
            }

            throw new DataTypeEnumerationException(propertyInstance.PropertyMapping.PropertyDefinition.DataType, "DataType not supported.");
        }
    }
}
